﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace backoffice
{
    public partial class orderForm : Form
    {
        int id; // id de la commande

        public orderForm()
        {
            InitializeComponent();
            this.id = 0;
        }

        public orderForm(int id)
        {
            InitializeComponent();
            this.id = id;
        }


        private void orderForm_Load(object sender, EventArgs e)
        {
            if (!id.Equals(0))
                populateAndBind();
        }

   
        /**
         * 
         * Remplit les input dans la visualisation
         * 
         */
        private void populateAndBind()
        {

            BU.OrderManager manager = new BU.OrderManager();
            BU.Order order = manager.getOne(id);

            tbOrder.Text = order.ID.ToString();
            tbDate.Text = order.Date.ToShortDateString();
            tbClient.Text = order.Customer.Name + " " + order.Customer.Firstname;
            PopulateAndBindOrderProducts();


        }

        /**
        * 
        * Remplit le panel des commandes
        * 
        **/


        private void PopulateAndBindOrderProducts()
        {

            BU.OrderManager cm = new BU.OrderManager();
            List<BU.OrderView> list = cm.getAllOrderProducts(id);
            dgvOrder.DataSource = list;
        }


        /**
        * 
        * Affiche les coordonnées du client
        * 
        **/
        private void btClient_Click(object sender, EventArgs e)
        {

            //???
            // utilisation du currency manager en cours

            DetailClientForm form = new DetailClientForm();

            DialogResult result = form.ShowDialog();
        
        }




    }
}
